import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../views/Layout/index.vue'
Vue.use(VueRouter)
// 解决官方bug（删除此处，报错信息：Navigation aborted from “/a“ to “/b“ via a navigation guard.）
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalPush.call(this, location, onResolve, onReject)
  }
  return originalPush.call(this, location).catch(err => err)
}
// ----------------------todos
//replace 解决官方bug（删除此处，报错信息：Navigation cancelled from "/aboutView" to "/testView" with a new navigation）
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject) {
    return originalReplace.call(this, location, onResolve, onReject)
  }
  return originalReplace.call(this, location).catch(err => err)
}


export const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login/index.vue'),
  },
  {
    name: 'layout1',
    path: '/',
    component: Layout,
    redirect: 'home',
    children: [
      {
        path: 'home',
        name: 'home',
        component: () => import('@/views/HomeView'),
      },
      // {
      //   path: 'test',
      //   name: 'test',
      //   component: () => import('../views/TestView/index.vue'),
      //   meta: {
      //     // keepAlive: true
      //   }
      // },
      // {
      //   path: 'bigTree',
      //   name: 'bigTree',
      //   component: () => import('../views/MyTree/index.vue'),
      //   meta: {
      //     // keepAlive: true
      //   }
      // },
      // {
      //   path: 'myDynamicItemForm',
      //   name: 'myDynamicItemForm',
      //   component: () => import('../views/MyDynamicItemForm/index.vue'),
      //   meta: {
      //     // keepAlive: true
      //   }
      // },
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.reloadRouter = function () {
  router.matcher = new VueRouter({
    mode: 'history',
    routes
  }).matcher
}
export default router
